export default async({ app, store }, inject) => {
    const UaParse = userAgent => ({
        is_wechat_client: userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger",
        isEdge: userAgent.includes("Edge"),
        isFF: userAgent.includes("Firefox"),
        isOpera: userAgent.includes("Opera"),
        isBB: userAgent.includes("BlackBerry"),
        isChrome: userAgent.includes("Chrome"),
        isMaxthon: userAgent.includes("Maxthon"),
        isIos: /(iPhone|iPad|iPod|iOS)/i.test(userAgent),
        isSafari: userAgent.includes("Safari") && !userAgent.includes("Chrome"),
        isIE: userAgent.includes("compatible") &&
            userAgent.includes("MSIE") &&
            !userAgent.includes("Opera"),
        isMobile: /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/gi.test(
            userAgent
        )
    });

    // 检查设备类型
    let userAgent = null;
    if (process.server) {
        if (app.context.req && app.context.req.headers) {
            userAgent = app.context.req.headers['user-agent']
        }
    } else {
        userAgent = navigator.userAgent;
    }
    if (userAgent) {
        const {
            is_wechat_client,
            isMobile,
            isOpera,
            isIE,
            isSafari,
            isEdge,
            isFF,
            isBB,
            isChrome,
            isMaxthon,
            isIos
        } = UaParse(userAgent);
        store.dispatch("app/setPlatForm", isMobile);
        inject('isMobile', isMobile)
    } else {
        store.dispatch("app/setPlatForm", true);
        inject('isMobile', true)
    }

}